package com.xiashitech.apiservice.util;

import java.util.*;
import java.io.*;
import cn.hutool.log.*;
import cn.hutool.poi.excel.*;
import lombok.var;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.collect.Lists;

public class XlsIoUtil {
    private static final Log log = LogFactory.get();

    public static List<Object[]> parseXls(MultipartFile file) {
        List<Object[]> result = Lists.newArrayList();
        try (var inputStream = file.getInputStream()) {
            var reader = ExcelUtil.getReader(inputStream, "Sheet1");
            var datalist = reader.readAll();
            for (var l : datalist) {
                var index = 0;
                var value = l.values();
                var values = new Object[value.size()];
                var iterator = value.iterator();
                while (iterator.hasNext()) {
                    values[index++] = iterator.next();
                }
                result.add(values);
            }
        } catch (IOException e) {
            log.error(e);
        }
        return result;
    }
}
